package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(name = "minio.endpoint")//该注解表达的含义是只有当`minio.endpoint`属性存在时，该配置类才会生效。
@EnableConfigurationProperties(minioproperties.class)
@Configuration
@RequiredArgsConstructor
public class MinioConfiguration {

    private final minioproperties properties;
    @Bean
    public MinioClient minioClient()
    {
        return MinioClient.builder()
                .endpoint(properties.getEndpoint())
                .credentials(properties.getAccessKey(),properties.getSecretKey())
                .build();
    }
}
